﻿@{
    ViewBag.Title = "AssignTeacher";
}
@{
    var courseInfo = ViewData["CourseInfo"] as CourseInfo;
    var teacherList = ViewData["TeacherList"] as IList<UserInfo>;
    var assignTeacherList = ViewData["AssignTeacherList"] as IList<string>;
    var rows = teacherList.Count / 4;
    if (teacherList.Count < 4)
    {
        rows = 1;
    }
    else if (teacherList.Count / 4 != 0)
    {
        rows += 1;
    }
}
@model CourseInfo
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>精品课程管理-新建课程</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav2.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">
                数据结构与算法<br>
                <small>广州中医药大学康复治疗微课程网络学习平台</small>
            </h1>
        </div>
    </div>
    @*导航菜单*@
    @Html.Partial("~/Views/Share/PublicAdminNaviMenu.cshtml", 1)
    <div class="container">
        <div class="row">
            <div class="col-xs-2">
                <div class="dropdown theme-dropdown clearfix">
                    <a id="dropdownMenu1" href="#" role="button" class="sr-only dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                        <li class="active" role="presentation">
                            <a role="menuitem" tabindex="-1" href="@Url.Action("CourseInfoList", "CourseInfo")">
                                <span class="glyphicon glyphicon-list"></span>课程列表
                            </a>
                        </li>
                        <li role="presentation" class="divider"></li>
                        <li role="presentation">
                            <a role="menuitem" tabindex="-1" href="@Url.Action("CourseInfoAdd", "CourseInfo")">
                                <span class="glyphicon glyphicon-plus"></span>新建课程
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="col-xs-10">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <ol class="breadcrumb">
                                <li>精品课程管理</li>
                                <li class="active">教师分配</li>
                            </ol>
                        </h3>
                    </div>
                    <div class="panel-body course_panel">
                        <div class="row toolbar1">
                            <button type="button" id="all" class="btn btn-sm btn-success">全选</button>
                            <button type="button" id="allNot" class="btn btn-sm btn-success">全不选</button>
                        </div>
                        <form id="frm" class="form-horizontal" role="form">
                            <div class="course_con" id="course_con">
                                @Html.Hidden("CourseId", courseInfo.Id)
                                @for (var i = 0; i < rows; i++)
                                {
                                    <div class="row">
                                        @for (int j = 0; j < 4 && (j + i * 4) < teacherList.Count(); j++)
                                        {
                                            <div class="col-xs-3">
                                                @if (assignTeacherList.Contains(teacherList[j + i * 3].Id))
                                                {
                                                    <input type="checkbox" checked value="@teacherList[j + i * 3].Id" id="@teacherList[j + i * 3].Id" name="UserId" />
                                                }
                                                else
                                                {
                                                    <input type="checkbox" value="@teacherList[j + i * 3].Id" id="@teacherList[j + i * 3].Id" name="UserId" />
                                                }
                                                <label for="@teacherList[j + i * 3].Id">@teacherList[j + i * 3].RealName</label>
                                            </div>
                                        }


                                    </div>
                                }
                            </div>
                        </form>
                    </div>
                    <div class="panel-footer clearfix">
                        <button type="button" onclick="autoSubmit('frm');" class="btn btn-success">保存</button>
                        <button type="button" onclick="history.go(-1)" class="btn btn-success btn-md"><span class="glyphicon glyphicon-arrow-left"></span>返回</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")

    <script src="~/Content/jquery.form.js"></script>

    <script>
        var t = true;
        function autoSubmit(frmId) {
            var postData = $("#" + frmId).formSerialize();
            var url = "@Url.Action("AssignTeacher", "CourseInfo")";
            var options = {
                type: 'POST',
                data: postData,
                url: url,
                async: false,
                cache: false,
                success: function (data) {
                    if (data.result) {
                        showTips.open("添加成功");
                    }
                    else {
                        showTips.open(data.message);
                    }
                }
            }
            if (t) {
                t = false;
                $.ajax(options);
                t = true;
            }
        };

        $(function () {
            $("#all").click(function () {
                $(":checkbox").prop("checked", true);
            });
            $("#allNot").click(function () {
                $(":checkbox").prop("checked", false);
            });
        });
    </script>
</body>
</html>












@*
    <h2>AssignTeacher</h2>
    @using (Html.BeginForm("AssignTeacher", "CourseInfo", FormMethod.Post))
    {
        @Html.Hidden("CourseId", courseInfo.Id);
        <fieldset>
            <legend>@courseInfo.CourseName</legend>
            @foreach (var teacher in teacherList)
            {
                <input type="checkbox" name="UserId" value="@teacher.Id" />@teacher.RealName
            }
        </fieldset>
        <input type="submit" value="提交" />
    }*@
